/*
* Copyright 2010 Dovado FZ-LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "DovadoRequestListener.h"

typedef enum call_codes_s {
	REQUEST_OK = 0,
	ILLEGAL_HOST,
	ILLEGAL_USER,
	ILLEGAL_PASSWORD,
	ILLEGAL_ALIAS,
	ILLEGAL_DIM_VALUE
} request_error_codes_t;

@interface DovadosNetworkRequest : NSObject <NSStreamDelegate> {

	@private
	NSString *mHost;
	NSString *mUsername;
	NSString *mPassword;
	NSInteger mPort;
	NSString *mCurrentAlias;
	NSInteger mCurrentDimValue;
	NSInteger mCurrentTokenValue;
	id<DovadoRequestListener> mListener;
	NSMutableArray *mGroupsArray;
	NSMutableArray *mAliasArray;
	NSMutableArray *mInfoArray;
	
}

@property (nonatomic, retain) NSString *mHost;
@property (nonatomic, retain) NSString *mUsername;
@property (nonatomic, retain) NSString *mPassword;
@property (nonatomic, retain) NSString *mCurrentAlias;
@property (nonatomic, retain) NSMutableArray *mGroupsArray;
@property (nonatomic, retain) NSMutableArray *mAliasArray;
@property (nonatomic, retain) NSMutableArray *mInfoArray;
@property (nonatomic, readwrite) NSInteger mPort;
@property (nonatomic, readwrite) NSInteger mCurrentDimValue;
@property (nonatomic, readwrite) NSInteger mCurrentTokenValue;

/*
 * Ctor that sets the host name and the port number to the router. 
 *
 * @param
 *		host the url or ip-address to the router, not null or empty string.
 *			 Will add a http:// prefix if it's missing. 
 *
 * @param
 *		port the port number
 */
- (id) initWithHost:(NSString*) host: (NSInteger) port;

/*
 * Set the username and password.
 * 
 * @param 
 *		username the username to the router, not null or empty string.
 *
 * @param 
 *		password the password to the router, not null or empty string. 
 */
- (void) setUserInformation:(NSString*) username: (NSString*) password: (id<DovadoRequestListener>) listener;



/*
 * The methods below sends asynchronous request to the router, callback will be made via 
 * the DovadoRequestListener interface when the request is done or has failed. 
 *
 * NOTE that the network request engine only support ONE network request at the time, 
 * there are no request queue!
 */

- (request_error_codes_t) requestAliases;
- (request_error_codes_t) requestGroups;
- (request_error_codes_t) requestGroupsAndAliases;
- (request_error_codes_t) requestSyncAll;
- (request_error_codes_t) requestInfo;
- (request_error_codes_t) requestTurnOn:(NSString*) alias;
- (request_error_codes_t) requestTurnOff:(NSString*) alias;
- (request_error_codes_t) requestDimAlias:(NSString*) alias: (NSInteger) value;


@end
